package org.rcgwt.client.ui.grid.model;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class BasicColumn implements IColumn {

    private int titleColSpan = 1;

    private final String name;

    private final String title;

    private boolean isSortable;

    private boolean isVisible;

    private int width;

    private int minWidth = -1;

    private int maxWidth = -1;

    private int percentWidth;

    private boolean resizable;

    public BasicColumn(String name, String title) {
        this.name = name;
        this.title = title;
    }

    public int getPercentWidth() {
        return percentWidth;
    }

    public void setPercentWidth(int percentWidth) {
        this.percentWidth = percentWidth;
    }

    @Override
    public int getTitleColSpan(int titleRowIndex) {
        return titleColSpan;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getMainTitle() {
        return title;
    }

    @Override
    public String getTitle(int rowIndex) {
        return getMainTitle();
    }

    @Override
    public boolean isSortable() {
        return isSortable;
    }

    @Override
    public boolean isVisible() {
        return isVisible;
    }

    @Override
    public boolean isResizable() {
        return resizable;
    }

    @Override
    public int getWidth() {
        return this.width;
    }

    public void setSortable(boolean isSortable) {
        this.isSortable = isSortable;
    }

    public void setVisible(boolean isVisible) {
        this.isVisible = isVisible;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setResizable(boolean resizable) {
        this.resizable = resizable;
    }

    @Override
    public int getMaxWidth() {
        return maxWidth;
    }

    @Override
    public int getMinWidth() {
        return minWidth;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof IColumn) {
            return ((IColumn) obj).getName().equals(name);
        }
        return false;
    }

    @Override
    public void setMaxWidth(int width) {
        maxWidth = width;
    }

    @Override
    public void setMinWidth(int width) {
        minWidth = width;
    }

    @Override
    public boolean isValidWidth(int width) {
        return ((((minWidth > -1) && (width >= minWidth)) || (minWidth < 0)) && (((maxWidth > -1) && (width <= maxWidth)) || (maxWidth < 0)));
    }
}
